import apiClient from './client'
import type { ProductReview } from '@/types/product'

export interface ReviewAddRequest {
  orderItemId: number
  rating: number
  comment: string
}

export const reviewService = {
  // 添加商品评价
  addReview: (reviewData: ReviewAddRequest) =>
    apiClient.post<ProductReview>('/api/v1/review/add', reviewData),

  // 删除商品评价
  deleteReview: (reviewId: number) =>
    apiClient.post('/api/v1/review/delete', { reviewId }),

  // 检查用户是否已评价指定订单项
  checkReviewExists: (orderItemId: number) =>
    apiClient.get('/api/v1/review/check-exists', { params: { orderItemId } }),

  // 获取商品评价列表
  getReviewList: (shoeId: number, page: number = 1, size: number = 10) =>
    apiClient.get('/api/v1/review/list', { params: { productId: shoeId, page, size } }),

  // 获取用户评价列表
  getUserReviewList: (page: number = 1, size: number = 10) =>
    apiClient.get('/api/v1/review/user-list', { params: { page, size } }),

  // 获取商品评价统计
  getReviewStatistics: (shoeId: number) =>
    apiClient.get('/api/v1/review/statistics', { params: { productId: shoeId } }),
}

export default reviewService
